import { RouteRecordRaw } from 'vue-router'
export function mapMenusToRoutes(userMenu: any[]): RouteRecordRaw[] {
  const routes: RouteRecordRaw[] = []

  const routeFiles = require.context('../router/main', true, /\.ts/)
  const allRoutes: any[] = []
  routeFiles.keys().forEach((key) => {
    const route = require('../router/main' + key.split('.')[1])
    allRoutes.push(route.default)
  })

  const _recurseGetRoute = (menus: any[]) => {
    for (const menu of menus) {
      const item = allRoutes.find((item) => item.name === menu.text)
      if (item) routes.push(item)
      if (menu?.children?.length) _recurseGetRoute(menu.children)
    }
  }

  _recurseGetRoute(userMenu)
  return routes
}
